﻿namespace DatabaseManage
{
    using System;
    using System.Collections.Generic;
    using System.Data;

    public abstract class AbsDatabaseInfo
    {
        private string _connectionString;

        protected AbsDatabaseInfo()
        {
        }

        public abstract bool CheckDatabaseConnection();
        public virtual string ConvertDbToCS(string dataType)
        {
            switch (dataType)
            {
                case "int identity":
                    return "int";

                case "bigint identity":
                    return "long";

                case "uniqueidentifier":
                    return "Guid";

                case "int":
                    return "int";

                case "smallint":
                    return "short";

                case "nvarchar":
                    return "string";

                case "varchar":
                    return "string";

                case "float":
                    return "double";

                case "money":
                    return "decimal";

                case "datetime":
                    return "DateTime";

                case "smalldatetime":
                    return "DateTime";

                case "decimal":
                    return "decimal";

                case "bigint":
                    return "long";

                case "char":
                    return "string";

                case "bit":
                    return "bool";

                case "smallmoney":
                    return "decimal";

                case "text":
                    return "string";

                case "ntext":
                    return "string";

                case "nchar":
                    return "string";

                case "image":
                    return "byte[]";

                case "varbinary":
                    return "byte[]";

                case "real":
                    return "float";

                case "tinyint":
                    return "byte";

                case "sql_variant":
                    return "object";

                case "binary":
                    return "object";
            }
            return "";
        }

        public virtual string ConvertDbToNHbm(string dataType)
        {
            switch (dataType)
            {
                case "int identity":
                    return "Int32";

                case "bigint identity":
                    return "Int32";

                case "uniqueidentifier":
                    return "Guid";

                case "int":
                    return "Int32";

                case "smallint":
                    return "Int32";

                case "nvarchar":
                    return "String";

                case "varchar":
                    return "String";

                case "float":
                    return "Double";

                case "money":
                    return "Decimal";

                case "datetime":
                    return "DateTime";

                case "smalldatetime":
                    return "DateTime";

                case "decimal":
                    return "Decimal";

                case "bigint":
                    return "Int32";

                case "char":
                    return "String";

                case "bit":
                    return "Boolean";

                case "smallmoney":
                    return "Decimal";

                case "text":
                    return "String";

                case "ntext":
                    return "String";

                case "nchar":
                    return "String";

                case "image":
                    return "Byte[]";

                case "varbinary":
                    return "Byte[]";

                case "real":
                    return "Single";

                case "tinyint":
                    return "Byte";

                case "sql_variant":
                    return "Object";

                case "binary":
                    return "Object";
            }
            return "";
        }

        public abstract DataTable GetDatabaseAllTableNames();
        public abstract DataTable GetDatabaseAllViewNames();
        public abstract List<FieldInfo> GetTableAllFieldInfos(string tableName);
        public abstract string GetTableCommentInfo(string tableName);
        public abstract List<FieldInfo> GetViewAllFieldInfos(string viewName);
        public abstract void SetConnectionString(string dbAdd, string dbName, string userName, string pwd);

        public string ConnectionString
        {
            get
            {
                return this._connectionString;
            }
            set
            {
                this._connectionString = value;
            }
        }
    }
}

